1 package org.smartcomps.twister.deployer; 2 3 import junit.framework.TestCase; 4 import org.dom4j.Document; 5 import org.dom4j.DocumentHelper; 6 import org.dom4j.Element; 7 import org.smartcomps.twister.common.transaction.TransactionManager; 8 import org.smartcomps.twister.common.lifecycle.LifecycleManager; 9 import org.smartcomps.twister.engine.priv.core.definition.TwisterProcess; 10 import org.smartcomps.twister.engine.priv.core.definition.ProcessFactory; 11 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance; 12 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory; 13 import org.smartcomps.twister.engine.priv.core.dynamic.impl.xao.VariableXAO; 14 import org.smartcomps.twister.engine.TwisterEngineFactory; 15 import org.smartcomps.twister.engine.TwisterEngine; 16 import org.smartcomps.twister.util.BeanTester; 17 18 import java.util.Map; 19 import java.util.HashMap; 20 21 import net.sf.hibernate.tool.hbm2ddl.SchemaExport; 22 import net.sf.hibernate.cfg.Configuration; 23 24 /*** 25 * had test ressources package in the classpath 26 */ 27 public class TestDeployer extends TestCase { 28 29 private TwisterDeployer deployer; 30 31 protected void setUp() throws Exception { 32 LifecycleManager.getLifecycleManager().createResources(); 33 LifecycleManager.getLifecycleManager().startResources(); 34 35 SchemaExport schemaExport = new SchemaExport(new Configuration().configure()); 36 schemaExport.create(true, true); 37 38 deployer = TwisterDeployerFactory.getTwisterDeployer(); 39 } 40 41 protected void tearDown() throws Exception { 42 deployer = null; 43 44 LifecycleManager.getLifecycleManager().stopResources(); 45 LifecycleManager.getLifecycleManager().destroyResources(); 46 } 47 48 public void testDeploy() throws Exception { 49 50 deployer.deploy(getClass().getClassLoader().getResource("loop.xml")); 51 // Deployer doesn't handle properties yet 52 TransactionManager.beginTransaction(); 53 TwisterProcess process = ProcessFactory.getByName("loop"); 54 // <property name="counterId" type="xsd:string"/> 55 // <propertyAlias propertyName="counterId" messageType="counterMsg" part="main" query="/counterId"/> 56 // ProcessFactory.addProperty(process, "counterId", "xsd:string", "counterMsg", "main", "/counterId"); 57 TransactionManager.commitTransaction(); 58 59 String counterId = (String)BeanTester.generateRandomValue(String.class); 60 Document doc = DocumentHelper.createDocument(); 61 Element root = doc.addElement("message").addElement("main"); 62 root.addElement("counter").setText("0"); 63 root.addElement("counterId").setText(counterId); 64 int result = TwisterEngineFactory.getEngine() 65 .acknowledge("loopPartner", "loopPort", "loopOp", doc); 66 assertEquals("Message controller didn't acknowledge the message properly, an error occured", 67 TwisterEngine.ACKNOWLEDGED, result); 68 69 System.out.println("Waiting a little while..."); 70 Thread.sleep(12000); 71 72 TransactionManager.beginTransaction(); 73 Map corrProp = new HashMap(); 74 corrProp.put("counterId", counterId); 75 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation("counterCorrel", corrProp); 76 assertNotNull("Could not find the created process instance from correlation", createdInstance); 77 assertEquals("Process instance is not properly terminated", ProcessInstance.COMPLETED, createdInstance.getStatus()); 78 assertEquals("The counter variable has not been incremented 10 times", 79 "10.0", VariableXAO.queryVariableValue("loop", "loopVar", createdInstance.getId(), "main", "/counter")); 80 TransactionManager.commitTransaction(); 81 82 } 83 }

This page was automatically generated by Maven